﻿using System.Data.Objects;
using System.Diagnostics;
using MShop.Core.Domain;
namespace MShop.Core.DataAccess
{
    public class ObjectContextProvider : IObjectContextProvider
    {
        private readonly ObjectContext dataContext;
        private readonly IConnectionStringProvider _ConnectionStringProvider;
        public ObjectContextProvider(IConnectionStringProvider connectionStringProvider)
        {
            _ConnectionStringProvider = connectionStringProvider;
            dataContext = new MShopEntities(_ConnectionStringProvider.ConnectionString);
        }

        public ObjectContext ObjectContext
        {
            get
            {
                return dataContext;
            }
        }

        public void Dispose()
        {
            Debug.WriteLine("disponsed at" +System.DateTime.Now.ToString());
            dataContext.Dispose();
        }
    }
}
